package com.zx._12_算法;

import java.util.ArrayList;
import java.util.List;

/**
 * 双向链表
 */
public class TwoLinkNode {

    public TwoLinkNode last;

    public int val;

    public TwoLinkNode next;

    public static TwoLinkNode getNodes(Integer... nums) {
        TwoLinkNode result = new TwoLinkNode();
        result.val = nums[0];

        TwoLinkNode last = result;

        for (int i = 1; i < nums.length; i++) {

            TwoLinkNode cur = new TwoLinkNode();
            cur.val = nums[i];
            cur.last = last;

            last.next = cur;
            last = cur;
        }
        return result;
    }

    public void print() {
        TwoLinkNode head = this;
        List<Integer> resList = new ArrayList<>();
        while (head != null) {
            resList.add(head.val);
            head = head.next;
        }
        System.out.println(resList);
    }

}
